
var HTTP = require('http.js')


var isLogin = function(callback) {
  if (!getApp().globalData.userInfo) {
    wx.navigateTo({
      url: '/pages/login/login',
    })
  } else {
    callback && callback()
  }
}

var login = function() {
  if (!getApp().globalData.userInfo){
    return
  }
  const h = HTTP.request({
    method: 'POST',
    url: '/miniapp/login',
    data: {
      actionType: 1,
      code: getApp().globalData.code,
      appId: 'wx0725a501ae43fc92',
      WXUserInfo: JSON.stringify(getApp().globalData.userInfo)
    },
  })
  h.then((res)=> {
    wx.setStorageSync("loginInfo", res.data)
    getApp().globalData.loginInfo = res.data
  }, (error) => {
    this.login()
  })
  
}

module.exports = {
  isLogin,
  login
}